#define _CRT_SECURE_NO_WARNINGS 1

#include"StrLib.h"

size_t my_strlen(const char* str)
{
	assert(str);

	int len = -1;
	while (*(str + ++len))
		;

	return (size_t)len;
}

char* my_strcpy(char* destination, const char* source)
{
	assert(destination && source);

	char* ret = destination;
	while (*ret++ = *source++)
		;

	return destination;
}

int my_strcmp(const char* str1, const char* str2)
{
	assert(str1 && str2);

	while (*str1 == *str2)
	{
		if (*str1 == '\0')
		{
			return 0;
		}
		str1++;
		str2++;
	}
	return *str1 - *str2;
}

char* my_strcat(char* destination, const char* source)
{
	assert(destination && source);

	char* ret = destination;
	while (*ret != '\0')
	{
		ret++;
	}
	while (*ret++ = *source++)
		;

	return destination;
}

char* my_strstr(const char* str1, const char* str2)
{
	assert(str1 && str2);
	char* location = (char*)str1;
	char* s1 = NULL;
	char* s2 = NULL;

	if (*str2 == '\0')
	{
		return (char*)str1;
	}

	while (*location)
	{
		s1 = location;
		s2 = (char*)str2;

		while (*s1 == *s2 && *s1 && *s2)
		{
			s1++;
			s2++;
		}
		if (*s2 == '\0')
		{
			return location;
		}

		location++;
	}
	
	return NULL;
}